import { defineStore } from 'pinia'

// 定义一个管理模态框状态的store
export const useModalStore = defineStore('modal', {
  state: () => ({
    showLoginModal: false,
    redirectPath: null, // 存储用户想要访问但需要登录的路径
  }),
  
  getters: {
    getLoginModalStatus: (state) => state.showLoginModal,
    getRedirectPath: (state) => state.redirectPath,
  },
  
  actions: {
    // 显示登录模态框
    openLoginModal(redirectPath = null) {
      this.showLoginModal = true;
      if (redirectPath) {
        this.redirectPath = redirectPath;
      }
    },
    
    // 关闭登录模态框
    closeLoginModal() {
      this.showLoginModal = false;
    },
    
    // 清除重定向路径
    clearRedirectPath() {
      this.redirectPath = null;
    }
  }
})
